﻿using System;
using System.Web.UI;
using Bingosoft.Modules.Demo.User;
using Bingosoft.Web.Utils;
using HHMMS.Core.Service;
using HHMMS.Core.Model;

namespace HHMMS.UI.Modules.SysParameter
{
    public partial class SysParameterEdit : FormPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack && !SmartForm.IsInsert())
            {
                var param = SYS_ParametersService.Instance.Single(Request.GetQuery<string>("ParamCode"));
                SmartForm.Fill(container, param);
                this.tbParamCode.ReadOnly = true;
            }
        }

        protected void SaveOrUpdateUser(object sender, EventArgs e)
        {
            SYS_Parameters param = null;
            if (SmartForm.IsInsert())
            {
                param = SYS_ParametersService.Instance.Single(this.tbParamCode.Text.Trim());
                if (param != null && !string.IsNullOrEmpty(param.ParamValue))
                {
                    ScriptHelper.Alert(this,"参数编码[" + this.tbParamCode.Text + "]已存在，请更改后再试！");
                    return;
                }
            }

            param = SmartForm.GetEntity<SYS_Parameters>(container);
            SYS_ParametersService.Instance.SaveOrUpdate(param);
            ScriptHelper.CloseDialog(this, "true");
        }
    }
}